<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

	class Admin extends Controller {
		
		function Admin()
		{
			parent::Controller();
			
			$this->load->library('administration');
			$this->template['module']	= 'album';
			$this->template['admin']		= true;
			$this->load->model('album_model', 'album');
		}
		
		function index()
		{
			
			$this->settings();
		}
		
		function settings($storage = null)
		{
			if (is_null($storage))
			{
				if ($post = $this->input->post('submit') )
				{
					$fields = array('storage', 'album_col_num', 'user_can_create', 'show_meta');
					
					foreach ($fields as $field)
					{
						if ( $this->input->post($field) !== false)
						{
							$this->album->set($field, $this->input->post($field));
						}
					}
					$this->session->set_flashdata('notification', __("Settings updated", $this->template['module']));	
					redirect('admin/album/settings');
				}
				else
				{

				
					$this->load->helper('directory');
					$this->template['storages'] = directory_map('application/modules/album/libraries');
					

					$this->layout->load($this->template, 'admin/settings');
				
				}
				
				
			}
			else
			{
				$this->load->library($storage);
				$fields = $this->$storage->fields;
				$field_inputs = array();
				$this->template['fields'] = $fields;
				foreach ($fields as $field)
				{
					$field_inputs[] = $field['input'];
				}
				$this->user->check_level($this->template['module'], LEVEL_DEL);
				if ($post = $this->input->post('submit') )
				{
					foreach ($field_inputs as $field)
					{
						if ( $this->input->post($field) !== false)
						{
							$this->album->set($field, $this->input->post($field));
						}
					}
					$this->session->set_flashdata('notification', __("Settings updated", $this->template['module']));	
					redirect('admin/album/settings/' . $storage);
				}
				else
				{
					$this->template['storage'] = $storage;
					$this->layout->load($this->template, 'admin/storage');
				}
			}
			
		}
	}

?>